<script setup lang="ts">
import { inject, ref } from 'vue'
const http: any = inject('http');
const loading = ref(true);

interface IWBDataModal {
    indexes: string;
    text: string;
    href: string;
    hot: string;
    type: string;
};

interface IZHDataModal {
    indexes: string;
    title: string;
    content: string;
    heat: string;
    href: string;
};

interface IBDDataModal {
    indexes: string;
    href: string;
    title: string;
    content: string;
    heat: string;
    imgSrc: string;
}

interface IDataModal {
    WBData: IWBDataModal[];
    ZHData: IZHDataModal[];
    BDData: IBDDataModal[];
}

interface IResultModal {
    code: number;
    data: IDataModal;
    msg: string;
}

const data = ref<IDataModal | null>(null);
http.get('/api/topSearch/get').then((res: IResultModal) => {
    if (res.code === 1) {
        data.value = res.data;
        loading.value = false;
    }
})
</script>
<template>
    <div class="topSearch" v-loading="loading">
        <el-row>
            <el-col :span="11">
                <el-card style="width: 100%">
                    <template #header>
                        <div class="card-header">
                            <h1>微博热搜</h1>
                        </div>
                    </template>
                    <p v-for="(item, index) in data?.WBData" :key="index" class="wbItem">
                        <span style="display:inline-block;width: 5%;">{{ item.indexes }}</span>
                        <el-link target='_blank' :href="item.href" type="primary" class="text">{{ item.text
                            }}</el-link>
                        <span class="type">{{ item.type }}</span>
                    </p>
                </el-card>
            </el-col>
            <el-col :span="11" :offset="2">
                <el-card style="width: 100%">
                    <template #header>
                        <div class="card-header">
                            <h1>知乎热搜</h1>
                        </div>
                    </template>
                    <p v-for="(item, index) in data?.ZHData" :key="index" class="wbItem">
                        <span style="display:inline-block;width: 5%;">{{ item.indexes }}</span>
                        <el-link target='_blank' :href="item.href" type="primary" class="text">{{ item.title
                            }}</el-link>
                        <span class="type">{{ item.heat }}</span>
                    </p>
                </el-card>
            </el-col>
        </el-row>
        <el-card style="width: 100%; margin-top: 20px;">
            <template #header>
                <div class="card-header">
                    <h1>百度热搜</h1>
                </div>
            </template>
            <div class="box">
                <ul>
                    <li style="list-style: none;" v-for="item in data?.BDData" :key="item.indexes">
                        <a :href="item.href" class="boxItem" target="_blank">
                            <div class="boxItemImg">
                                <div class="index">{{ item.indexes }}</div>
                                <el-image lazy :src="item.imgSrc" fit="contain" />
                            </div>
                            <div class="boxItemContent">
                                <div class="title">{{ item.title }}</div>
                                <div class="content">{{ item.content }}</div>
                            </div>
                            <div class="heat">
                                {{ item.heat }}
                            </div>
                        </a>
                    </li>
                </ul>
            </div>
        </el-card>
    </div>
</template>

<style scoped>
.wbItem {
    display: flex;
    align-items: center;
    margin-top: 10px;
}

.wbItem .text {
    width: 70%;
    justify-content: left;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.wbItem .type {
    margin-left: 20px;
    font-size: 12px;
    padding: 0 3px;
    background-color: #ff9406;
    color: #fff;
    border-radius: 2px;
}

.box .boxItem {
    display: flex;
    padding: 10px 0;
}


.box .boxItem .boxItemImg {
    position: relative;
    width: 150px;
    height: 100px;
    border-radius: 8px;
    overflow: hidden;
    margin-right: 20px;
}

.box .boxItem .boxItemImg .index {
    position: absolute;
    top: 0;
    left: 0;
    width: 20px;
    height: 20px;
    border-radius: 8px 1px 8px 1px;
    font-size: 14px;
    line-height: 20px;
    text-align: center;
    background-color: #fe2d46;
    color: #fff;
    z-index: 999;
}

.box .boxItem .boxItemContent {
    flex: 1;
}

.box .boxItem .boxItemContent .title {
    font-size: 18px;
    padding-top: 10px;
    padding-bottom: 15px;
}

.box .boxItem .boxItemContent .content {
    font-size: 13px;
    /* color: #626675; */
}

.box .boxItem .heat {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 10%;
    border-left: 1px solid #eee;
    padding-left: 20px;
    margin-left: 20px;
    font-size: 16px;
    color: #9195a3;
}
</style>